import { defineNuxtRouteMiddleware } from '#app'

export default defineNuxtRouteMiddleware((to, from) => {
  const cmpName = (to.name as string)?.split('___')[0]
  if (cmpName !== 'index' || to.path === '/') return
  const lang = to.path.split('/').filter(Boolean)[0] || 'en'
  useCookie('i18n_redirected', { path: '/', maxAge: 60 * 60 * 24 * 30 }).value = lang
})
